package com.yeswater.multithread.chapter8;

import java.util.HashMap;
import java.util.Hashtable;

/**
 * author： yeswater
 * create： 2023/11/9
 *
 * 目的是：验证 hashTable 是线程安全的
 *  这种验证没有意义  不出现问题 不代表没问题……
 */
public class Run_8_2_2 {
    public static void main(String[] args) {
        Service1 service = new Service1();
        Thread1 t1 = new Thread1(service);
        Thread1 t2 = new Thread1(service);
        
        t1.start();
        t2.start();
    }
    
    private static class Service1 {
        public Hashtable map = new Hashtable<>();
        
        public void testMethod() {
            for (int i = 0; i < 50000; i++) {
                map.put(Thread.currentThread().getName() + " " + (i + 1), Thread.currentThread().getName() + " " + (i + 1));
                //System.out.println(Thread.currentThread().getName() + " " + (i + 1));
            }
        }
    }
    
    public static class Thread1 extends Thread{
        private Service1 service;
        
        public Thread1(Service1 service) {
            this.service = service;
        }
    
        @Override
        public void run() {
            service.testMethod();
            System.out.println("run end");
        }
    }
    
}
